import React, {useState, useEffect,} from 'react'
import BasketballModel from "../../../model/basketball";
import Admin from "../../../layout/Admin";
import {Table} from "antd";


const BasketballLiveList = props => {

    const model = new BasketballModel()
    const [list, setList,] = useState([])
    useEffect(() => {
        model.live().then(resp => setList(resp.data.ok))
    }, [])

    const switchLiveStatus = (game) => {
        model.switchLive({
            Id: game.Id,
            Source: game.Isshow === 0 ? 1 : 0,
        }).then(resp => {
            if (resp.data.ok === 1) {
                // setList([])
                const i = list.findIndex(g => g.Id === game.Id)
                list[i].Isshow = game.Isshow === 0 ? 1 : 0
                setList([...list])
            }
        })
    }
    const columns = [
        {
            title: '比赛',
            render: (_, record) => `${record.Name} ${record.Kename} ${record.Zhuname}`,
        },

        {
            title: '操作',
            render: (_, record) => {
                return <div>
                    <a
                        onClick={() => switchLiveStatus(record)}
                        style={{marginRight: '8px',}}
                    >{record.Isshow === 0 ? '关闭直播' : '开启直播'}</a>
                </div>
            }
        },
    ]

    return <Admin>
        <div
            className='list-container'
        >
            <Table
                rowKey={(record, index) => index}
                dataSource={list}
                columns={columns}
            />

        </div>
    </Admin>

}

export default BasketballLiveList